<%--
  Created by IntelliJ IDEA.
  User: Douliusuo
  Date: 2022/4/30
  Time: 20:30
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>编辑员工信息</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css" media="all">
        <link rel="stylesheet" href="${pageContext.request.contextPath}/css/public.css" media="all">
        <script src="${pageContext.request.contextPath}/js/jquery-3.6.0.min.js"></script>
        <style>
            body {
                background-color: #ffffff;
            }
        </style>
    </head>
    <body>
        <div class="layui-form layuimini-form">
            <div class="layui-form-item">
                <label class="layui-form-label required">员工编号</label>
                <div class="layui-input-block">
                    <input type="text" name="empno" lay-verify="required" lay-reqtext="员工职务不能为空" placeholder="请输入员工职务" value="" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">员工职务</label>
                <div class="layui-input-block">
                    <input type="text" name="job" lay-verify="required" lay-reqtext="员工职务不能为空" placeholder="请输入员工职务" value="" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">上司编号</label>
                <div class="layui-input-block">
                    <input type="text" name="mgr" placeholder="请输入上司编号" value="" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">员工薪资</label>
                <div class="layui-input-block">
                    <input type="number" name="sal" placeholder="请输入员工薪资" value="" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">年终奖金</label>
                <div class="layui-input-block">
                    <input type="number" name="comm" placeholder="请输入员工年终奖金" value="" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">部门编号</label>
                <div class="layui-input-block">
                    <input type="number" name="deptno" placeholder="请输入员工所在部门编号" value="" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">备注信息</label>
                <div class="layui-input-block">
                    <textarea name="remark" class="layui-textarea" placeholder="请输入备注信息"></textarea>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认提交</button>
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">返回主页面</button>
                </div>
            </div>
        </div>
        </div>
        <script src="${pageContext.request.contextPath}/layui/layui.js" charset="utf-8"></script>
        <script>
            layui.use(['form'], function () {
                var form = layui.form,
                    layer = layui.layer,
                    $ = layui.$;

                //监听提交
                form.on('submit(saveBtn)', function (data) {
                    data = data.field;
                    $.ajax({
                        url:'${pageContext.request.contextPath}/emp/updateEmp',
                        data:{
                            'empno':data.empno,
                            'job':data.job,
                            'mgr':data.mgr,
                            'sal':data.sal,
                            'comm':data.comm,
                            'deptno':data.deptno,
                        },
                        success:function (result) {
                            if (result == "1"){
                                layer.msg('修改成功', {icon: 1});
                                // 跳转回主页面
                                window.location='${pageContext.request.contextPath}/user/main';
                            }else {
                                layer.msg('修改失败', {icon: 2});
                            }
                        },
                        error:function () {
                            layer.msg('请求失败', {icon: 2});
                        }
                    });

                    return false;
                });

            });
        </script>
    </body>
</html>